//
//  UserGuideViewController.m
//  哎游
//
//  Created by 林程杰 on 15/1/14.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "UserGuideViewController.h"
#import "WebColor.h"
#import "MainViewController.h"
#import <ShareSDK/ShareSDK.h>
#import "sinaWiboViewController.h"
#import "Masonry.h"
#import "WebColor.h"
#import "registerViewController.h"
#import "LocalViewController.h"

@implementation UserGuideViewController

- (instancetype) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void) viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initGuide];
}

- (void) initGuide
{
    self.imageBig = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _imageBig.image = [UIImage imageNamed:@"LaunchScreen.png"];
    _imageBig.userInteractionEnabled = YES;
    [self.view addSubview:_imageBig];
    
    
    self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height *3 / 4)];
    _scroll.contentSize = CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height *3 / 4);
    _scroll.pagingEnabled = YES;
    _scroll.userInteractionEnabled = YES;
    _scroll.showsHorizontalScrollIndicator = NO;
    _scroll.showsVerticalScrollIndicator = NO;
    _scroll.delegate =self;

    
    if (_scroll.contentOffset.x == _scroll.frame.size.width) {
        _scroll.scrollEnabled = NO;
    }
    
    
    [self.view addSubview:_scroll];
    [self.view addSubview:_page];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    
    
    imageView.image = [UIImage imageNamed:@"big.png"];
    [_scroll addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scroll.mas_left).offset(_scroll.frame.size.width / 2 - 50);
        make.top.equalTo(self.view.mas_top).offset(self.view.frame.size.height / 4);
        make.size.mas_equalTo(CGSizeMake(95, 95));
    }];
    
    [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(appear:) userInfo:nil repeats:NO];// 1
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(_scroll.frame.size.width / 2 - 80, _scroll.frame.size.height * 3 / 4, 400, 30)];
    [_label setText:@"一 起 旅 游  .  享 受 生 活"];
    _label.font = [UIFont systemFontOfSize:13];
    [_label setTextColor:[UIColor whiteColor]];
    [_label setBackgroundColor:[UIColor clearColor]];
    _label.tag = 100;
    [_scroll addSubview:_label];
    //加入主标题
    
    UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width * 1.24, self.view.frame.size.height / 6.5, self.view.frame.size.width * 3 / 2, 150)];
    [labelTitle setText:@"哎 游"];
    [labelTitle setTextColor:[UIColor whiteColor]];
    [labelTitle setBackgroundColor:[UIColor clearColor]];
    labelTitle.font = [UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:80];//设置字体样式
    [_scroll addSubview:labelTitle];
    
    UILabel *labelDetil = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width *1.24, self.view.frame.size.height / 2.5, self.view.frame.size.width *3 / 2, 30)];
    [labelDetil setText:@"爱   •   就  一  起  旅  游  吧"];
    [labelDetil setTextColor:[UIColor whiteColor]];
    labelDetil.backgroundColor = [UIColor clearColor];
    labelDetil.font = [UIFont systemFontOfSize:15];
    [_scroll addSubview:labelDetil];
    
    
    
    //返回按钮
    UIButton *buttonBack = [[UIButton alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];

    [buttonBack setBackgroundColor:[UIColor clearColor]];

    [buttonBack addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonBack];
    
  
    [labelTitle release];
    [labelDetil release];
    [imageView release];
    [buttonBack release];
}


//动态图
- (void) appear : (NSTimer *) timer
{
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width / 3, _scroll.frame.size.height / 3, 5, 5)];
    // (110, 130, 5, 5)];
    image.image = [UIImage imageNamed:@"earth.png"];
    [_scroll addSubview:image];
    
    [UIImageView beginAnimations:@"第一个" context:nil];
    [UIImageView setAnimationDuration:0.7];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image.frame = CGRectMake(_scroll.frame.size.width / 3 - 10, _scroll.frame.size.height / 3 - 10, 23, 23);//变大会右移和下移, 改变坐标(-5, -5)
    
    [UIImageView commitAnimations];
    
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(appear2:) userInfo:nil repeats:NO];// 2
    
    [image release];
}

- (void) appear2 : (NSTimer *) timer
{
    UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width / 4, self.view.frame.size.height / 3, 5, 5)];
    
    image2.image = [UIImage imageNamed:@"heart.png"];
    
    [UIImageView beginAnimations:@"第二个" context:nil];
    [UIImageView setAnimationDuration:0.7];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image2.frame = CGRectMake(_scroll.frame.size.width / 4 - 10, self.view.frame.size.height / 3 - 10, 23, 23);
    
    [UIImageView commitAnimations];
    
    [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(appear3:) userInfo:nil repeats:NO]; //3
    
    [_scroll addSubview:image2];
    [image2 release];
}

- (void) appear3 : (NSTimer *) timer
{
    UIImageView *image3 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width * 2 / 3 + 5, _scroll.frame.size.height / 2, 5, 5)];
    
    image3.image = [UIImage imageNamed:@"mp3.png"];
    
    [UIImageView beginAnimations:@"第三个" context:nil];
    [UIImageView setAnimationDuration:0.7];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image3.frame = CGRectMake(_scroll.frame.size.width * 2 / 3 - 10, _scroll.frame.size.height / 2 - 10, 23, 23);
    
    [UIImageView commitAnimations];
    
    [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(appear4:) userInfo:nil repeats:NO]; //4
    
    [_scroll addSubview:image3];
    [image3 release];
}

- (void) appear4 : (NSTimer *) timer
{
    UIImageView *image4 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width *2.7 / 4, self.view.frame.size.height / 4, 5, 5)];
    
    image4.image = [UIImage imageNamed:@"pic.png"];
    
    [UIImageView beginAnimations:@"第四个" context:nil];
    [UIImageView setAnimationDuration:0.4];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image4.frame = CGRectMake(_scroll.frame.size.width *2.7 / 4, self.view.frame.size.height / 4, 14, 14);
    
    [UIImageView commitAnimations];
    
    [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(appear5:) userInfo:nil repeats:NO]; //5
    
    [_scroll addSubview:image4];
    [image4 release];
}

- (void) appear5 : (NSTimer *) timer
{
    UIImageView *image5 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width / 2.8, _scroll.frame.size.height / 1.8, 5, 5)];
    
    image5.image = [UIImage imageNamed:@"dangerous.png"];
    
    [UIImageView beginAnimations:@"第五个" context:nil];
    [UIImageView setAnimationDuration:0.4];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image5.frame = CGRectMake(_scroll.frame.size.width / 2.8 - 10, _scroll.frame.size.height / 1.8 - 10, 14, 14);
    
    [UIImageView commitAnimations];
    
    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(appear6:) userInfo:nil repeats:NO]; //6
    
    [_scroll addSubview:image5];
    [image5 release];
}

- (void) appear6 : (NSTimer *) timer
{
    UIImageView *image6 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width / 2 , _scroll.frame.size.height / 4, 5, 5)];
    
    image6.image = [UIImage imageNamed:@"weixin.png"];
    [UIImageView beginAnimations:@"第六个" context:nil];
    [UIImageView setAnimationDuration:0.4];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image6.frame = CGRectMake(_scroll.frame.size.width / 2 - 10, _scroll.frame.size.height / 4 - 10, 14, 14);
    
    [UIImageView commitAnimations];
    
    
    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(appear7:) userInfo:nil repeats:NO]; //7
    
    [_scroll addSubview:image6];
    [image6 release];
}

- (void) appear7 : (NSTimer *) timer
{
    UIImageView *image7 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width *1.8 / 3, _scroll.frame.size.height / 1.7, 5, 5)];
    
    image7.image = [UIImage imageNamed:@"small.png"];
    [UIImageView beginAnimations:@"第七个" context:nil];
    [UIImageView setAnimationDuration:0.2];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image7.frame = CGRectMake(_scroll.frame.size.width *1.8 / 3 - 10, _scroll.frame.size.height / 1.7 - 10, 14, 14);
    
    [UIImageView commitAnimations];
    
    
    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(appear8:) userInfo:nil repeats:NO]; //8
    
    [_scroll addSubview:image7];
    [image7 release];
}

- (void) appear8 : (NSTimer *) timer
{
    UIImageView *image8 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width / 1.7, _scroll.frame.size.height / 3.4, 5, 5)];
    
    image8.image = [UIImage imageNamed:@"sina.png"];
    
    [UIImageView beginAnimations:@"第八个" context:nil];
    [UIImageView setAnimationDuration:0.3];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image8.frame = CGRectMake(_scroll.frame.size.width / 1.7 - 10, _scroll.frame.size.height / 3.4 - 10, 14, 14);
    
    [UIImageView commitAnimations];
    
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(appear9:) userInfo:nil repeats:NO]; //9
    
    [_scroll addSubview:image8];
    [image8 release];
}

- (void) appear9 : (NSTimer *) timer
{
    UIImageView *image9 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width *3.8 / 5, self.view.frame.size.height / 3, 5, 5)];
    
    image9.image = [UIImage imageNamed:@"message.png"];
    [UIImageView beginAnimations:@"第九个" context:nil];
    [UIImageView setAnimationDuration:0.6];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image9.frame = CGRectMake(_scroll.frame.size.width *3.8 / 5 - 10, self.view.frame.size.height / 3 - 10, 23, 23);
    
    [UIImageView commitAnimations];
    
    [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(appear10:) userInfo:nil repeats:NO]; //10
    
    [_scroll addSubview:image9];
    [image9 release];
}

- (void) appear10 : (NSTimer *) timer
{
    UIImageView *image10 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width *3.3 / 5, _scroll.frame.size.height / 5, 5, 5)];
    image10.image = [UIImage imageNamed:@"camera.png"];
    [UIImageView beginAnimations:@"第十个" context:nil];
    [UIImageView setAnimationDuration:0.7];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image10.frame = CGRectMake(_scroll.frame.size.width *3.3 / 5 - 10, _scroll.frame.size.height / 5 - 10, 23, 23);
    
    [UIImageView commitAnimations];
    
    
    [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(appear11:) userInfo:nil repeats:NO]; //10
    
    [_scroll addSubview:image10];
    [image10 release];
}

- (void) appear11 : (NSTimer *) timer
{
    UIImageView *image11 = [[UIImageView alloc] initWithFrame:CGRectMake(_scroll.frame.size.width / 2.3, self.view.frame.size.height / 2.2, 5, 5)];
    image11.image = [UIImage imageNamed:@"foot.png"];
    [UIImageView beginAnimations:@"第十一个" context:nil];
    [UIImageView setAnimationDuration:0.7];
    [UIImageView setAnimationRepeatAutoreverses:NO];
    [UIImageView setAnimationRepeatCount:NAN];
    image11.frame = CGRectMake(_scroll.frame.size.width / 2.3 - 10, self.view.frame.size.height / 2.2 - 10, 23, 23);
    
    [UIImageView commitAnimations];
    
    //自动滚动的动画
    
    [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(appear12:) userInfo:nil repeats:NO]; //11
    
    [_scroll addSubview:image11];
    [image11 release];
}

- (void) appear12 : (NSTimer *) timer
{
    [UIScrollView beginAnimations:@"13213" context:nil];
    [UIScrollView setAnimationDuration:1];
    [UIScrollView setAnimationRepeatCount:NAN];
    [UIScrollView setAnimationRepeatAutoreverses:NO];
    _scroll.contentOffset = CGPointMake(_scroll.frame.size.width, 0);
    self.page.currentPage = _scroll.contentOffset.x / self.scroll.frame.size.width;
    [UIScrollView commitAnimations];
    
}

- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.page.currentPage = scrollView.contentOffset.x / self.scroll.frame.size.width;
}




- (void) back
{
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    [userDefaults setValue:[NSNumber numberWithBool:YES] forKey:@"firstTime"];
    [self.view removeFromSuperview];
    
    _guideBlock();
}

- (void)getGuideBlock:(GuideViewControllerBlock)block
{
    self.guideBlock = block;
}



@end
